{template '_header'}

<div class="page-header">
    当前位置：<span class="text-primary">{if !empty($item['id'])}编辑{else}添加{/if}运营商</span>
</div>

<div class="page-content">
    <div class="page-sub-toolbar">
        <span class=''>
		{ifp 'manage.operator.add'}
                <a class="btn btn-primary btn-sm" href="{php echo webUrl('operator/post')}">添加新运营商</a>
            {/if}
            <a class="btn btn-default  btn-sm" href="{php echo webUrl('operator')}">返回列表</a>
        </span>
    </div>

<form id="setform"  {ifp 'manage.operator.edit'}action="" method="post"{/if} class="form-horizontal form-validate">

<input type="hidden" name="id" value="{$item['id']}" />

<div class="tabs-container">
    <div class="tab-content ">
        <div class="tab-pane active" id="tab_basic">

            <div class="form-group">
                <label class="col-sm-2 control-label must">投资人姓名</label>
                <div class="col-sm-8">
                    {ifp 'manage.operator.edit'}
                    <input type="text" class="form-control" name="nickname" value="{$item['nickname']}" data-rule-required="true"/>
                    {else}
                    <div class="form-control-static">
                        {$item['nickname']}
                    </div>
                    {/if}
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-2 control-label must">账号</label>
                <div class="col-sm-8">
                    {ifp 'manage.operator.edit'}
                    <input type="text" class="form-control" name="account" value="{$item['account']}" data-rule-required="true"/>
                    {else}
                    <div class="form-control-static">
                        {$item['account']}
                    </div>
                    {/if}
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-2 control-label">密码</label>
                <div class="col-sm-8">
                    {ifp 'manage.operator.edit'}
                    <input type="password" class="form-control" name="password" value="" />
                    {if !empty($item['id'])}<span class="help-block text-danger">不修改密码请留空</span>{/if}
                    {else}
                    <div class="form-control-static">               </div>
                    {/if}
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-2 control-label">图片</label>
                <div class="col-sm-8">
                    {ifp 'manage.operator.edit'}
                    {php echo tpl_form_field_image('thumb',$item['thumb'],'../addons/mx_shop/static/images/nopic.jpg')}
                    {else}
                    {if empty($item['thumb'])}
                    <img src="../addons/mx_shop/static/images/nopic.jpg" onerror="this.src='../addons/mx_shop/static/images/nopic.jpg'; this.title='图片未找到.'" class="img-responsive img-thumbnail" width="150">
                    {else}
                    <img src="{php echo tomedia($item['thumb'])}" onerror="this.src='../addons/mx_shop/static/images/nopic.jpg'; this.title='图片未找到.'" class="img-responsive img-thumbnail" width="150">
                    {/if}
                    {/if}
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-2 control-label must">运营商级别</label>
                <div class="col-sm-8">
                    {ifp 'manage.operator.edit'}
                    <select name='type' class='form-control ' id="seltype">
                        <option value="0" {if empty($item['type'])} selected  {/if}>请选择级别</option>
                        {loop $types $k $v}
                        <option value="{$v['type']}" {if $v['type'] == $item['type']} selected  {/if}>{$v['name']}</option>
                        {/loop}
                    </select>
                    {else}
                    <div class="form-control-static">
                        {loop $types $k $v}
                            {if $v['type'] == $item['type']}
                                {$v['name']}
                            {/if}
                        {/loop}
                    </div>
                    {/if}
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-2 control-label">负责区域</label>
                <div class="col-sm-9 col-xs-12">
                    {ifp 'manage.operator.edit'}
                    <p>
                        <select id="selcountry" name="country" onChange="loadArea(this, 3);" class="select form-control" style="width:130px;display:inline;">
                            <option value="" selected="true">请选择国</option>
                            {loop $country $row}
                            <option value="{$row['name']}" {if $row['name']==$item['country']}selected="selected"{/if}>{$row['name']}</option>
                            {/loop}
                        </select>
                        <select id="selprov" name="province" onChange="loadArea(this, 2);" class="select form-control" style="width:130px;display:inline;">
                            <option value="" selected="true">请选择省</option>
                            {loop $province $row}
                            <option value="{$row['name']}" {if $row['name']==$item['province']}selected="selected"{/if}>{$row['name']}</option>
                            {/loop}
                        </select>
                        <select id="selcity" name="city" onChange="loadArea(this, 1);" class="select form-control" style="width:135px;display:inline;">
                            <option value="" selected="true">请选择市</option>
                            {loop $city $row}
                            <option value="{$row['name']}" {if $row['name']==$item['city']}selected="selected"{/if}>{$row['name']}</option>
                            {/loop}
                        </select>
                        <select id="seldist" name="dist" class="select form-control" style="width:130px;display:inline;">
                            <option value="" selected="true">请选择区</option>
                            {loop $area $row}
                            <option value="{$row['name']}" {if $row['name']==$item['area']}selected="selected"{/if}>{$row['name']}</option>
                            {/loop}
                        </select>
                    </p>
                    {else}
                    <div class='form-control-static'>{$item['country']} {$item['province']} {if $item['type'] == 2} {$item['city']} {$item['dist']}{/if}</div>
                    {/if}
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-2 control-label">状态</label>
                <div class="col-sm-8">
                    {ifp 'manage.operator.edit'}
                    <label class="radio-inline">
                        <input type="radio" name="status" value="1" {if $item['status']==1}checked{/if} />启用
                    </label>
                    <label class="radio-inline">
                        <input type="radio" name="status" value="0" {if $item['status']==0}checked{/if}/> 禁用
                    </label>
                    {else}
                    <div class="form-control-static">
                        {if $item['status']==0}
                        禁用
                        {elseif $item['stauts']==1}
                        启用
                        {/if}
                    </div>
                    {/if}
                </div>
            </div>
        </div>
    </div>
</div>

{ifp 'manage.operator.edit'}
<div class="form-group">
    <label class="col-sm-2 control-label"></label>
    <div class="col-sm-9 col-xs-12">
        <input type="submit"  value="提交" class="btn btn-primary" />
    </div>
</div>
{/if}

</form>

<script>
    var _type = "{$item['type']}";
    if(_type == 8){
        $('#selcity').hide();
        $('#seldist').hide();
    }
    $('#seltype').change(function(){
        var _val = $(this).val();
        if(_val == 8){
            $('#selcity').hide();
            $('#seldist').hide();
        }else{
            $('#selcity').show();
            $('#seldist').show();
        }
    });

    function loadArea(obj, num){
        var area = {};
        var addobj = '';
        var str = '';
        if(num >= 1){
            str = '<option value="0">请选择区</option>';
            $('#seldist').html(str);
            addobj = '#seldist';
        }

        if(num >= 2){
            str = '<option value="0">请选择市</option>';
            $('#selcity').html(str);
            addobj = '#selcity';
        }

        if(num >= 3){
            str = '<option value="0">请选择省</option>';
            $('#selprov').html(str);
            addobj = '#selprov';
        }

        area.country = $('#selcountry').val();
        area.province = $('#selprov').val();
        area.city = $('#selcity').val();
        if($(obj).val() != 0){
            $.post("{php echo webUrl('manage/operator/opajax')}", area, function (data) {
                if (data.status == 1) {
                    var json = data.data;
                    var _html = str;
                    for (var o in json) {
                        if (json[o].name != '') {
                            _html += '<option value="' + json[o].name + '">' + json[o].name + '</option>';
                        }
                    }
                    $(addobj).html(_html);
                }

            }, 'json')
        }
    }
</script>
</div>
{template '_footer'}